package com.heritage.repository;

import com.heritage.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface CommentRepository extends JpaRepository<Comment, Long> {
    @Query("SELECT c FROM Comment c JOIN FETCH c.user WHERE c.heritage.id = :heritageId ORDER BY c.createdAt DESC")
    List<Comment> findByHeritageIdOrderByCreatedAtDesc(@Param("heritageId") Long heritageId);
}
